dwr.engine.setTimeout(30000); //TODO<vpolischuk>: Probably for development it's a bad idea.
dwr.engine.setErrorHandler(dwrErrorHandle);

dwr.engine.setPreHook(function() {
    $("#loading").css("visibility", "visible");
});

dwr.engine.setPostHook(function() {
    $("#loading").css("visibility", "hidden");
});

function dwrErrorHandle(message, exception) {
    $("#loading").css("visibility", "hidden");
    $("#dwrErrorDialog").find("p").remove();

    var height = 200;
    var width = 600;

    if (exception.messages) {
        for (var m in exception.messages) {
            $("#dwrErrorDialog").append("<p>" + exception.messages[m] + "</p>");
        }
    } else {
        $("#dwrErrorDialog").append("<p>" + message + "</p>");
    }

    if (exception.stringStackTrace) {
        $("#dwrErrorDialog").append("<pre>" + exception.stringStackTrace + "</pre>");
        height = 700;
        width = 800;
    }

    showAlertDialog($("#dwrErrorDialog"), null, width, height);
}

